var entry=angular.module("entry",[]);
entry.directive('entry',function($http,$location,$rootScope){
    return {
        restrict : 'EA',
        transclude : true,
        scope : {
            conf : '='
        },
        templateUrl:'page/directive/entry.html'+ '?datestamp=' + (new Date()).getTime(),
        link : function(scope, element, attrs) {
            scope.conf.showEntryContent=false;
            var basePath= scope.$parent.basePath;
            scope.conf.verifyCode= basePath+'login/getAuthCode.do?name='+Math.random();
            scope.hideTipContent = function() {
                scope.conf.showEntryContent =false;
            }

            scope.changeCode=function(){
                scope.conf.verifyCode=basePath+'login/getAuthCode.do?name='+Math.random();
            }

            scope.login=function(){
                var pwd=scope.conf.passWord;
                var  email= scope.conf.user.userName;
                var length=pwd.length;
                var pwdMd5= hex_md5(email+length+pwd).substring(16) ;
                scope.conf.user.passWord=pwdMd5;
                $http({
                    method  : 'POST',
                    url     : basePath+'login/login.do',
                    data    : $.param(scope.conf.user),
                    dataType:'json',
                    headers : {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                    .success(function(data) {
                        if (data.respCode=='success') {
                            $rootScope.$emit("userId", data.dataObject.id);
                            $location.path('/home');
                        } else {
                            alert(data.respMsg);
                            scope.conf.verifyCode=basePath+'login/getAuthCode.do?name='+Math.random();
                        }
                    });

                /*待删*/
                /*    $location.path('/home');*/
            }
        }
    }
})

entry.directive('pathContent',function($http,$location,$rootScope){
    return {
        restrict : 'E',
        transclude : true,
        scope:{
            cur:'=cur'//双向绑定用=
        },
        templateUrl:'page/directive/path.html'+ '?datestamp=' + (new Date()).getTime(),
        link : function(scope, element, attrs) {
            scope.$watch('cur', function(newVal){
                var index=parseInt(newVal)-1;
                element.find(".common-point-content").removeClass("active-point-content");
                element.find(".common-point-content").eq(index).addClass("blue-point-content");
                element.find(".common-point-content").eq(index).addClass("active-point-content");
                for(var i=0;i<index;i++){
                    element.find(".common-point-content").eq(i).addClass("blue-point-content");
                    element.find(".common-line-content").eq(i).addClass("blue-line-content");
                }
            })

        }
    }
})
